﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DynamicButtons
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ButtonsView : Window
    {
        private int curRow = 0;
        public ButtonsView()
        {
            InitializeComponent();
           
        }
        private void AddRow(double height)
        {
            MyGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(height) });
        }
     
        public void AddButton(string text, RoutedEventHandler ac)
        {
            System.Windows.Controls.Button btn = new System.Windows.Controls.Button();
            btn.Content = text;
            btn.Click += ac;

            AddRow(40);

            Grid.SetRow(btn, curRow++);
            Grid.SetColumn(btn, 0);
            MyGrid.Children.Add(btn);
        }
    }
}
